package com.lwz.laboratory.controller;


import com.lwz.laboratory.entity.Register;
import com.lwz.laboratory.entity.User;
import com.lwz.laboratory.service.RecruitplanService;
import com.lwz.laboratory.service.RegisterService;
import com.lwz.laboratory.service.SignupService;
import com.lwz.laboratory.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.UUID;

@Controller
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    @Autowired
    private UserService userService;






    @RequestMapping("/toregister")
    public String toregister() {


        return "register";
    }

    @RequestMapping("/register")
    public String register(MultipartFile file, Register register)throws IOException {

        String filePath = "C:\\Users\\15122\\Desktop\\boot期末\\spring boot end\\src\\main\\resources\\static\\images\\";
        //获取原始图片的拓展名

        String originalFilename = file.getOriginalFilename();
        //新的文件名字
        String newFileName = UUID.randomUUID() + originalFilename;
        //封装上传文件位置的全路径
        File targetFile = new File(filePath, newFileName);
        //把本地文件上传到封装上传文件位置的全路径
        file.transferTo(targetFile);
        register.setPhoto(newFileName);
        User user =new User();
        user.setUserid(register.getStuid());
        user.setName(register.getName());
        user.setPassword(register.getPassword());
        user.setRolename("学生");
        userService.adduser(user);
        registerService.Register(register);
        return "login";
    }
}
